//解析歌词工具函数

//匹配歌词时间的正则
const timeRegExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/

export function parseLyric(lyricString) {
  const lyricStrings = lyricString.split("\n")
  const lyricInfos = []

  for (const lineString of lyricStrings) {
    const timeResult = timeRegExp.exec(lineString)
    if (!timeResult) continue

    //获取时间
    const minute = timeResult[1] * 60 * 1000
    const second = timeResult[2] * 1000
    const millsecend = timeResult[3].length === 2 ? timeResult[3] * 10 : timeResult[3] * 1
    const time = minute + second + millsecend

    //获取歌词文本
    const text = lineString.replace(timeRegExp, "")
    lyricInfos.push({
      time,
      text
    })

  }

  return lyricInfos
}